package methodObj;
public class Demo2ObjectArray {
    public static void main(String[] args) {
        //创建对象数组
        Student[] students=new Student[3];
        //创建三个对象   java 17可以  11不可以
       students[1]=new Student("张三",75);
       students[2]=new Student("李四",80);
       students[3]=new Student("王二",65);

        //冒泡排序
        for(int j=0;j<students.length-1;j++){
            for(int i=0;i<students.length-1-j;i++) {
                if(students[i].getScore()>students[i+1].getScore()){
                    Student temp=students[i];
                    students[i]=students[i+1];
                    students[i+1]=temp;
                }

            }
        }
        //循环打印结果
        for (int i = 0; i < students.length; i++) {
            System.out.println(students[i].getName()+" "+students[i].getScore());
        }
    }
}
